<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Text::Autoformat - Automatic text wrapping and reformatting - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Text-Autoformat - MetaCPAN" href="https://metacpan.org/dist/Text-Autoformat/releases.rss" />
        <link rel="canonical" href="./Text::Autoformat.html" />
        <meta name="description" content="Automatic text wrapping and reformatting" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Text::Autoformat" />
<meta name="twitter:title"       content="Text::Autoformat" />
<meta name="twitter:description" content="Automatic text wrapping and reformatting" />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Text::Autoformat.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Text-Autoformat was released.">
      <span class="relatize">13 Aug 2019 10:43:04 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Text-Autoformat">Text-Autoformat</a>
  </li>
  <li>
    Module version: 1.75
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Text-Autoformat/source/lib/Text/Autoformat.pm">Source</a>
    (<a href="https://metacpan.org/dist/Text-Autoformat/source/lib/Text/Autoformat.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Text-Autoformat/source/lib/Text">Browse</a>
    (<a href="https://metacpan.org/dist/Text-Autoformat/source/lib/Text?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Text-Autoformat/changes">Changes</a>
    </li>
    <li>
      <a rel="noopener nofollow" class="nopopup" href="https://github.com/neilb/Text-Autoformat">Homepage</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Text-Autoformat/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/neilb/Text-Autoformat">Repository</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Text-Autoformat">Issues</a>
      (21)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Text-Autoformat+1.75" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/T/Text-Autoformat.html?oncpan=1&amp;distmat=1&amp;version=1.75&amp;grade=2" style="color: #090">112</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/T/Text-Autoformat.html?oncpan=1&amp;distmat=1&amp;version=1.75&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/T/Text-Autoformat.html?oncpan=1&amp;distmat=1&amp;version=1.75&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/NEILB/Text-Autoformat-1.75">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Text-Autoformat who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 2
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Text-Autoformat-1.75/index.html">55.52% Coverage </a>
    </li>
    <li>
      License: perl_5
    </li>
    <li>
      Perl: v5.6.0
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Text-Autoformat/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/N/NE/NEILB/Text-Autoformat-1.75.tar.gz">
      Download (<span itemprop="fileSize">28.93KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FNEILB%2FText-Autoformat-1.75%2Flib%2FText%2FAutoformat.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Text-Autoformat/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Text-Autoformat/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Text-Autoformat">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Text-Autoformat">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Text/Autoformat.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="NEILB/Text-Autoformat-1.75"
>1.75
  (NEILB on 2019-08-13)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669006"
>1.669006
  (DCONWAY on 2014-10-03)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669005"
>1.669005
  (DCONWAY on 2014-10-03)</option>
<optgroup label="BackPAN">'
<option
  
  value="NEILB/Text-Autoformat-1.74"
>1.74
  (NEILB on 2015-11-28)</option>
<option
  
  value="NEILB/Text-Autoformat-1.73"
>1.73
  (NEILB on 2015-11-08)</option>
<option
  
  value="NEILB/Text-Autoformat-1.72"
>1.72
  (NEILB on 2015-06-14)</option>
<option
  
  value="NEILB/Text-Autoformat-1.71_01"
>1.71_01 DEV
  (NEILB on 2015-06-06)</option>
<option
  
  value="NEILB/Text-Autoformat-1.71"
>1.71
  (NEILB on 2015-05-04)</option>
<option
  
  value="NEILB/Text-Autoformat-1.70"
>1.70
  (NEILB on 2015-05-01)</option>
<option
  
  value="NEILB/Text-Autoformat-1.69_01"
>1.69_01 DEV
  (NEILB on 2015-04-25)</option>
<option
  
  value="NEILB/Text-Autoformat-1.69"
>1.69
  (NEILB on 2015-02-15)</option>
<option
  
  value="NEILB/Text-Autoformat-1.68"
>1.68
  (NEILB on 2015-02-15)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669007"
>1.669007
  (DCONWAY on 2015-02-09)</option>
<option
  
  value="NEILB/Text-Autoformat-1.67"
>1.67
  (NEILB on 2015-01-08)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669004"
>1.669004
  (DCONWAY on 2013-07-31)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669003"
>1.669003
  (DCONWAY on 2013-05-13)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669002"
>1.669002
  (DCONWAY on 2010-06-22)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669001"
>1.669001
  (DCONWAY on 2010-05-30)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.668001"
>1.668001
  (DCONWAY on 2010-04-03)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.666.0"
>1.666.0
  (DCONWAY on 2009-04-16)</option>
<option
  
  value="DCONWAY/Text-Autoformat-v1.14.0"
>v1.14.0
  (DCONWAY on 2007-09-29)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.13"
>1.13
  (DCONWAY on 2005-05-04)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.12"
>1.12
  (DCONWAY on 2003-05-27)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.11"
>1.11
  (DCONWAY on 2003-05-07)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.10"
>1.10
  (DCONWAY on 2003-04-09)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.08"
>1.08
  (DCONWAY on 2003-04-02)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.07"
>1.07
  (DCONWAY on 2003-04-02)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.04"
>1.04
  (DCONWAY on 2000-12-04)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.03"
>1.03
  (DCONWAY on 2000-10-25)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.02"
>1.02
  (DCONWAY on 2000-08-05)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/NEILB/Text-Autoformat-1.75/diff/' + encodeURIComponent(this.value) + '/lib/Text/Autoformat.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="NEILB/Text-Autoformat-1.75"
>1.75
  (NEILB on 2019-08-13)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669006"
>1.669006
  (DCONWAY on 2014-10-03)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669005"
>1.669005
  (DCONWAY on 2014-10-03)</option>
<optgroup label="BackPAN">'
<option
  
  value="NEILB/Text-Autoformat-1.74"
>1.74
  (NEILB on 2015-11-28)</option>
<option
  
  value="NEILB/Text-Autoformat-1.73"
>1.73
  (NEILB on 2015-11-08)</option>
<option
  
  value="NEILB/Text-Autoformat-1.72"
>1.72
  (NEILB on 2015-06-14)</option>
<option
  
  value="NEILB/Text-Autoformat-1.71_01"
>1.71_01 DEV
  (NEILB on 2015-06-06)</option>
<option
  
  value="NEILB/Text-Autoformat-1.71"
>1.71
  (NEILB on 2015-05-04)</option>
<option
  
  value="NEILB/Text-Autoformat-1.70"
>1.70
  (NEILB on 2015-05-01)</option>
<option
  
  value="NEILB/Text-Autoformat-1.69_01"
>1.69_01 DEV
  (NEILB on 2015-04-25)</option>
<option
  
  value="NEILB/Text-Autoformat-1.69"
>1.69
  (NEILB on 2015-02-15)</option>
<option
  
  value="NEILB/Text-Autoformat-1.68"
>1.68
  (NEILB on 2015-02-15)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669007"
>1.669007
  (DCONWAY on 2015-02-09)</option>
<option
  
  value="NEILB/Text-Autoformat-1.67"
>1.67
  (NEILB on 2015-01-08)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669004"
>1.669004
  (DCONWAY on 2013-07-31)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669003"
>1.669003
  (DCONWAY on 2013-05-13)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669002"
>1.669002
  (DCONWAY on 2010-06-22)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669001"
>1.669001
  (DCONWAY on 2010-05-30)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.668001"
>1.668001
  (DCONWAY on 2010-04-03)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.666.0"
>1.666.0
  (DCONWAY on 2009-04-16)</option>
<option
  
  value="DCONWAY/Text-Autoformat-v1.14.0"
>v1.14.0
  (DCONWAY on 2007-09-29)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.13"
>1.13
  (DCONWAY on 2005-05-04)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.12"
>1.12
  (DCONWAY on 2003-05-27)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.11"
>1.11
  (DCONWAY on 2003-05-07)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.10"
>1.10
  (DCONWAY on 2003-04-09)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.08"
>1.08
  (DCONWAY on 2003-04-02)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.07"
>1.07
  (DCONWAY on 2003-04-02)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.04"
>1.04
  (DCONWAY on 2000-12-04)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.03"
>1.03
  (DCONWAY on 2000-10-25)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.02"
>1.02
  (DCONWAY on 2000-08-05)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="https://metacpan.org/pod/Carp" title="Carp" class="ellipsis">Carp</a></li>
  <li><a href="https://metacpan.org/pod/Exporter" title="Exporter" class="ellipsis">Exporter</a></li>
  <li><a href="https://metacpan.org/pod/Text::Reform" title="Text::Reform" class="ellipsis">Text::Reform</a></li>
  <li><a href="https://metacpan.org/pod/Text::Tabs" title="Text::Tabs" class="ellipsis">Text::Tabs</a></li>
  <li><a href="https://metacpan.org/pod/overload" title="overload" class="ellipsis">overload</a></li>
  <li><a href="https://metacpan.org/pod/strict" title="strict" class="ellipsis">strict</a></li>
  <li><a href="https://metacpan.org/pod/warnings" title="warnings" class="ellipsis">warnings</a></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Text::Autoformat/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Text%3A%3AAutoformat">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Text-Autoformat">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/NEILB/Text-Autoformat-1.75/view/lib/Text/Autoformat.pm">This version</a>
    </li>
    <li>
      <a href="./Text::Autoformat.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/ZMUGHAL"><img src="https://www.gravatar.com/avatar/82e7c54d334bfdfd32594d34583d32bc?d=identicon&amp;s=20" title="ZMUGHAL" alt="ZMUGHAL"></a>
<a class="display-all" href="https://metacpan.org/author/AZAWAWI"><img src="https://www.gravatar.com/avatar/70ebafdecf974e15bcaba4cbe39efef1?d=identicon&amp;s=20" title="AZAWAWI" alt="AZAWAWI"></a>
<a class="display-all" href="https://metacpan.org/author/ADAMJS"><img src="https://www.gravatar.com/avatar/62c7b6e864d6509cff5839543c676614?d=identicon&amp;s=20" title="ADAMJS" alt="ADAMJS"></a>
<a class="display-all" href="https://metacpan.org/author/BEROV"><img src="https://www.gravatar.com/avatar/eae0eb4092a9f63426c13408e343b803?d=identicon&amp;s=20" title="BEROV" alt="BEROV"></a>
<a class="display-all" href="https://metacpan.org/author/AYOUNG"><img src="https://www.gravatar.com/avatar/8d1e4946c288fbe87d1e0394f3e41b24?d=identicon&amp;s=20" title="AYOUNG" alt="AYOUNG"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Text-Autoformat/plussers">7 PAUSE users</a>
</div>
<div>
    4 non-PAUSE users
</div>
</div>
    </li>
    <li>
<div id="metacpan_contributors">
  <div>
    <button class="btn-link"
      onclick="$(this).hide(); $('#metacpan_contributors ul').slideDown(); return false;"
    >and 1 contributors</button>
  </div>
  <ul style="display: none">
    <li class="contributor"
      data-cpan-author="DCONWAY"
      data-contrib-email="damian@conway.org"
    >
      <a href="https://metacpan.org/author/DCONWAY" class="cpan-author">
      <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/3d4a6a089964a744d7b3cf2415f81951?d=identicon&amp;s=20" />
      Damian Conway
      </a>
    </li>
  </ul>
</div>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/NEILB" class="author-name">Neil Bowers</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Text/Autoformat.pm&#39;" class="">
<option
  selected
  value="NEILB/Text-Autoformat-1.75"
>1.75
  (NEILB on 2019-08-13)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669006"
>1.669006
  (DCONWAY on 2014-10-03)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669005"
>1.669005
  (DCONWAY on 2014-10-03)</option>
<optgroup label="BackPAN">'
<option
  
  value="NEILB/Text-Autoformat-1.74"
>1.74
  (NEILB on 2015-11-28)</option>
<option
  
  value="NEILB/Text-Autoformat-1.73"
>1.73
  (NEILB on 2015-11-08)</option>
<option
  
  value="NEILB/Text-Autoformat-1.72"
>1.72
  (NEILB on 2015-06-14)</option>
<option
  
  value="NEILB/Text-Autoformat-1.71_01"
>1.71_01 DEV
  (NEILB on 2015-06-06)</option>
<option
  
  value="NEILB/Text-Autoformat-1.71"
>1.71
  (NEILB on 2015-05-04)</option>
<option
  
  value="NEILB/Text-Autoformat-1.70"
>1.70
  (NEILB on 2015-05-01)</option>
<option
  
  value="NEILB/Text-Autoformat-1.69_01"
>1.69_01 DEV
  (NEILB on 2015-04-25)</option>
<option
  
  value="NEILB/Text-Autoformat-1.69"
>1.69
  (NEILB on 2015-02-15)</option>
<option
  
  value="NEILB/Text-Autoformat-1.68"
>1.68
  (NEILB on 2015-02-15)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669007"
>1.669007
  (DCONWAY on 2015-02-09)</option>
<option
  
  value="NEILB/Text-Autoformat-1.67"
>1.67
  (NEILB on 2015-01-08)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669004"
>1.669004
  (DCONWAY on 2013-07-31)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669003"
>1.669003
  (DCONWAY on 2013-05-13)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669002"
>1.669002
  (DCONWAY on 2010-06-22)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.669001"
>1.669001
  (DCONWAY on 2010-05-30)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.668001"
>1.668001
  (DCONWAY on 2010-04-03)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.666.0"
>1.666.0
  (DCONWAY on 2009-04-16)</option>
<option
  
  value="DCONWAY/Text-Autoformat-v1.14.0"
>v1.14.0
  (DCONWAY on 2007-09-29)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.13"
>1.13
  (DCONWAY on 2005-05-04)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.12"
>1.12
  (DCONWAY on 2003-05-27)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.11"
>1.11
  (DCONWAY on 2003-05-07)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.10"
>1.10
  (DCONWAY on 2003-04-09)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.08"
>1.08
  (DCONWAY on 2003-04-02)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.07"
>1.07
  (DCONWAY on 2003-04-02)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.04"
>1.04
  (DCONWAY on 2000-12-04)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.03"
>1.03
  (DCONWAY on 2000-10-25)</option>
<option
  
  value="DCONWAY/Text-Autoformat-1.02"
>1.02
  (DCONWAY on 2000-08-05)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Text-Autoformat">Text-Autoformat-1.75</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage two &#10;
          • 20 direct dependents &#10;          • 62 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="10"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Text-Autoformat-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Text-Autoformat-1.75">
    <input type="hidden" name="author" value="NEILB">
    <input type="hidden" name="distribution" value="Text-Autoformat">
    <button type="submit" class="favorite highlight"><span>11</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Text::Autoformat.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>11</span> ++</a>
</div>
   / <span>Text::Autoformat</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Text::Autoformat.html#NAME">NAME</a></li>
  <li><a href="./Text::Autoformat.html#VERSION">VERSION</a></li>
  <li><a href="./Text::Autoformat.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Text::Autoformat.html#BACKGROUND">BACKGROUND</a>
    <ul>
      <li><a href="./Text::Autoformat.html#The-problem">The problem</a></li>
      <li><a href="./Text::Autoformat.html#The-solution">The solution</a></li>
    </ul>
  </li>
  <li><a href="./Text::Autoformat.html#DESCRIPTION">DESCRIPTION</a>
    <ul>
      <li><a href="./Text::Autoformat.html#Paragraphs">Paragraphs</a></li>
      <li><a href="./Text::Autoformat.html#Bulleting-and-(re-)numbering">Bulleting and (re-)numbering</a></li>
      <li><a href="./Text::Autoformat.html#Quoting">Quoting</a></li>
      <li><a href="./Text::Autoformat.html#Widow-control">Widow control</a></li>
      <li><a href="./Text::Autoformat.html#Justification">Justification</a></li>
      <li><a href="./Text::Autoformat.html#Implicit-centring">Implicit centring</a></li>
      <li><a href="./Text::Autoformat.html#Case-transformations">Case transformations</a></li>
      <li><a href="./Text::Autoformat.html#Selective-reformatting">Selective reformatting</a></li>
      <li><a href="./Text::Autoformat.html#Handling-tabs">Handling tabs</a></li>
    </ul>
  </li>
  <li><a href="./Text::Autoformat.html#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="./Text::Autoformat.html#REPOSITORY">REPOSITORY</a></li>
  <li><a href="./Text::Autoformat.html#AUTHOR">AUTHOR</a></li>
  <li><a href="./Text::Autoformat.html#BUGS">BUGS</a></li>
  <li><a href="./Text::Autoformat.html#LICENCE-AND-COPYRIGHT">LICENCE AND COPYRIGHT</a></li>
  <li><a href="./Text::Autoformat.html#DISCLAIMER-OF-WARRANTY">DISCLAIMER OF WARRANTY</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Text::Autoformat - Automatic text wrapping and reformatting</p>

<h1 id="VERSION">VERSION</h1>

<p>This document describes version 1.72 of Text::Autoformat</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code> # Minimal use: read from STDIN, format to STDOUT...

    use Text::Autoformat;
    autoformat;

 # In-memory formatting...

    $formatted = autoformat $rawtext;

 # Configuration...

    $formatted = autoformat $rawtext, { %options };

 # Margins (1..72 by default)...

    $formatted = autoformat $rawtext, { left=&gt;8, right=&gt;70 };

 # Justification (left by default)...

    $formatted = autoformat $rawtext, { justify =&gt; &#39;left&#39; };
    $formatted = autoformat $rawtext, { justify =&gt; &#39;right&#39; };
    $formatted = autoformat $rawtext, { justify =&gt; &#39;full&#39; };
    $formatted = autoformat $rawtext, { justify =&gt; &#39;centre&#39; };

 # Filling (does so by default)...

    $formatted = autoformat $rawtext, { fill=&gt;0 };

 # Squeezing whitespace (does so by default)...

    $formatted = autoformat $rawtext, { squeeze=&gt;0 };

 # Select appropriate tabspacing (default is 8 spaces per tab):

    $formatted = autoformat $rawtext, { tabspace=&gt;4 };

 # Case conversions...

    $formatted = autoformat $rawtext, { case =&gt; &#39;lower&#39; };
    $formatted = autoformat $rawtext, { case =&gt; &#39;upper&#39; };
    $formatted = autoformat $rawtext, { case =&gt; &#39;sentence&#39; };
    $formatted = autoformat $rawtext, { case =&gt; &#39;title&#39; };
    $formatted = autoformat $rawtext, { case =&gt; &#39;highlight&#39; };
    $formatted = autoformat $rawtext, { case =&gt; \&amp;my_case_func };

 # Selective reformatting

    $formatted = autoformat $rawtext, { ignore=&gt;qr/^\t/ };</code></pre>

<h1 id="BACKGROUND">BACKGROUND</h1>

<h2 id="The-problem"><a id="The"></a>The problem</h2>

<p>Perl plaintext formatters just aren&#39;t smart enough. Given a typical piece of plaintext in need of formatting:</p>

<pre><code>        In comp.lang.perl.misc you wrote:
        : &gt; &lt;CN = Clooless Noobie&gt; writes:
        : &gt; CN&gt; PERL sux because:
        : &gt; CN&gt;    * It doesn&#39;t have a switch statement and you have to put $
        : &gt; CN&gt;signs in front of everything
        : &gt; CN&gt;    * There are too many OR operators: having |, || and &#39;or&#39;
        : &gt; CN&gt;operators is confusing
        : &gt; CN&gt;    * VB rools, yeah!!!!!!!!!
        : &gt; CN&gt; So anyway, how can I stop reloads on a web page?
        : &gt; CN&gt; Email replies only, thanks - I don&#39;t read this newsgroup.
        : &gt;
        : &gt; Begone, sirrah! You are a pathetic, Bill-loving, microcephalic
        : &gt; script-infant.
        : Sheesh, what&#39;s with this group - ask a question, get toasted! And how
        : *dare* you accuse me of Ianuphilia!</code></pre>

<p>both the venerable Unix <a href="https://metacpan.org/pod/fmt">fmt</a> tool and Perl&#39;s standard Text::Wrap module produce:</p>

<pre><code>        In comp.lang.perl.misc you wrote:  : &gt; &lt;CN = Clooless Noobie&gt;
        writes:  : &gt; CN&gt; PERL sux because:  : &gt; CN&gt;    * It doesn&#39;t
        have a switch statement and you have to put $ : &gt; CN&gt;signs in
        front of everything : &gt; CN&gt;    * There are too many OR
        operators: having |, || and &#39;or&#39; : &gt; CN&gt;operators is confusing
        : &gt; CN&gt;    * VB rools, yeah!!!!!!!!!  : &gt; CN&gt; So anyway, how
        can I stop reloads on a web page?  : &gt; CN&gt; Email replies only,
        thanks - I don&#39;t read this newsgroup.  : &gt; : &gt; Begone, sirrah!
        You are a pathetic, Bill-loving, microcephalic : &gt;
        script-infant.  : Sheesh, what&#39;s with this group - ask a
        question, get toasted! And how : *dare* you accuse me of
        Ianuphilia!</code></pre>

<p>Other formatting modules -- such as Text::Correct and Text::Format -- provide more control over their output, but produce equally poor results when applied to arbitrary input. They simply don&#39;t understand the structural conventions of the text they&#39;re reformatting.</p>

<h2 id="The-solution"><a id="The1"></a>The solution</h2>

<p>The Text::Autoformat module provides a subroutine named <code>autoformat</code> that wraps text to specified margins. However, <code>autoformat</code> reformats its input by analysing the text&#39;s structure, so it wraps the above example like so:</p>

<pre><code>        In comp.lang.perl.misc you wrote:
        : &gt; &lt;CN = Clooless Noobie&gt; writes:
        : &gt; CN&gt; PERL sux because:
        : &gt; CN&gt;    * It doesn&#39;t have a switch statement and you
        : &gt; CN&gt;      have to put $ signs in front of everything
        : &gt; CN&gt;    * There are too many OR operators: having |, ||
        : &gt; CN&gt;      and &#39;or&#39; operators is confusing
        : &gt; CN&gt;    * VB rools, yeah!!!!!!!!! So anyway, how can I
        : &gt; CN&gt;      stop reloads on a web page? Email replies
        : &gt; CN&gt;      only, thanks - I don&#39;t read this newsgroup.
        : &gt;
        : &gt; Begone, sirrah! You are a pathetic, Bill-loving,
        : &gt; microcephalic script-infant.
        : Sheesh, what&#39;s with this group - ask a question, get toasted!
        : And how *dare* you accuse me of Ianuphilia!</code></pre>

<p>Note that the various quoting conventions have been observed. In fact, their structure has been used to determine where some paragraphs begin. Furthermore <code>autoformat</code> correctly distinguished between the leading &#39;*&#39; bullets of the nested list (which were outdented) and the leading emphatic &#39;*&#39; of &quot;*dare*&quot; (which was inlined).</p>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<h2 id="Paragraphs">Paragraphs</h2>

<p>The fundamental task of the <code>autoformat</code> subroutine is to identify and rearrange independent paragraphs in a text. Paragraphs typically consist of a series of lines containing at least one non-whitespace character, followed by one or more lines containing only optional whitespace. This is a more liberal definition than many other formatters use: most require an empty line to terminate a paragraph. Paragraphs may also be denoted by bulleting, numbering, or quoting (see the following sections).</p>

<p>Once a paragraph has been isolated, <code>autoformat</code> fills and re-wraps its lines according to the margins that are specified in its argument list. These are placed after the text to be formatted, in a hash reference:</p>

<pre><code>        $tidied = autoformat($messy, {left=&gt;20, right=&gt;60});</code></pre>

<p>By default, <code>autoformat</code> uses a left margin of 1 (first column) and a right margin of 72.</p>

<p>You can also control whether (and how) <code>autoformat</code> breaks words at the end of a line, using the <code>&#39;break&#39;</code> option:</p>

<pre><code>    # Turn off all hyphenation
    use Text::Autoformat qw(autoformat break_wrap);
        $tidied = autoformat($messy, {break=&gt;break_wrap});

    # Default hyphenation
    use Text::Autoformat qw(autoformat break_at);
        $tidied = autoformat($messy, {break=&gt;break_at(&#39;-&#39;)});

    # Use TeX::Hyphen module&#39;s hyphenation (module must be installed)
    use Text::Autoformat qw(autoformat break_TeX);
        $tidied = autoformat($messy, {break=&gt;break_TeX});</code></pre>

<p>Normally, <code>autoformat</code> only reformats the first paragraph it encounters, and leaves the remainder of the text unaltered. This behaviour is useful because it allows a one-liner invoking the subroutine to be mapped onto a convenient keystroke in a text editor, to provide one-paragraph-at-a-time reformatting:</p>

<pre><code>        % cat .exrc

        map f !Gperl -MText::Autoformat -e&#39;autoformat&#39;</code></pre>

<p>(Note that to facilitate such one-liners, if <code>autoformat</code> is called in a void context without any text data, it takes its text from <code>STDIN</code> and writes its result to <code>STDOUT</code>).</p>

<p>To enable <code>autoformat</code> to rearrange the entire input text at once, the <code>all</code> argument is used:</p>

<pre><code>        $tidied_all = autoformat($messy, {left=&gt;20, right=&gt;60, all=&gt;1});</code></pre>

<p><code>autoformat</code> can also be directed to selectively reformat paragraphs, using the <code>ignore</code> argument:</p>

<pre><code>        $tidied_some = autoformat($messy, {ignore=&gt;qr/^[ \t]/});</code></pre>

<p>The value for <code>ignore</code> may be a <code>qr</code>&#39;d regex, a subroutine reference, or the special string <code>&#39;indented&#39;</code>.</p>

<p>If a regex is specified, any paragraph whose original text matches that regex will not be reformatted (i.e. it will be printed verbatim).</p>

<p>If a subroutine is specified, that subroutine will be called once for each paragraph (with <code>$_</code> set to the paragraph&#39;s text). The subroutine is expected to return a true or false value. If it returns true, the paragraph will not be reformatted.</p>

<p>If the value of the <code>ignore</code> option is the string <code>&#39;indented&#39;</code>, <code>autoformat</code> will ignore any paragraph in which <i>every</i> line begins with a whitespace.</p>

<p>You may also specify multiple <code>ignore</code> options by including them in an array-ref:</p>

<pre><code>        $tidied_mesg = autoformat($messy, {ignore=&gt;[qr/1/,&#39;indented&#39;]});</code></pre>

<p>One other special case of ignorance is ignoring mail headers and signature. This option is specified using the <code>mail</code> argument:</p>

<pre><code>        $tidied_mesg = autoformat($messy_mesg, {mail=&gt;1});</code></pre>

<p>Note that the <code>ignore</code> or <code>mail</code> options automatically imply <code>all</code>.</p>

<h2 id="Bulleting-and-(re-)numbering"><a id="Bulleting"></a><a id="Bulleting-and--re--numbering"></a>Bulleting and (re-)numbering</h2>

<p>Often plaintext will include lists that are either:</p>

<pre><code>        * bulleted,
        * simply numbered (i.e. 1., 2., 3., etc.), or
        * hierarchically numbered (1, 1.1, 1.2, 1.3, 2, 2.1. and so forth).</code></pre>

<p>In such lists, each bulleted item is implicitly a separate paragraph, and is formatted individually, with the appropriate indentation:</p>

<pre><code>        * bulleted,
        * simply numbered (i.e. 1., 2., 3.,
          etc.), or
        * hierarchically numbered (1, 1.1,
          1.2, 1.3, 2, 2.1. and so forth).</code></pre>

<p>More importantly, if the points are numbered, the numbering is checked and reordered. For example, a list whose points have been rearranged:</p>

<pre><code>        1. Analyze problem
        3. Design algorithm
        1. Code solution
        5. Test
        4. Ship</code></pre>

<p>would be renumbered automatically by <code>autoformat</code>:</p>

<pre><code>        1. Analyze problem
        2. Design algorithm
        3. Code solution
        4. Test
        5. Ship</code></pre>

<p>The same reordering would be performed if the &quot;numbering&quot; was by letters (<code>a.</code> <code>b.</code> <code>c.</code> etc.) or Roman numerals (<code>i.</code> <code>ii.</code> <code>iii.)</code> or by some combination of these (<code>1a.</code> <code>1b.</code> <code>2a.</code> <code>2b.</code> etc.) Handling disordered lists of letters and Roman numerals presents an interesting challenge. A list such as:</p>

<pre><code>        A. Put cat in box.
        D. Close lid.
        E. Activate Geiger counter.</code></pre>

<p>should be reordered as <code>A.</code> <code>B.</code> <code>C.,</code> whereas:</p>

<pre><code>        I. Put cat in box.
        D. Close lid.
        XLI. Activate Geiger counter.</code></pre>

<p>should be reordered <code>I.</code> <code>II.</code> <code>III.</code></p>

<p>The <code>autoformat</code> subroutine solves this problem by always interpreting alphabetic bullets as being letters, unless the full list consists only of valid Roman numerals, at least one of which is two or more characters long.</p>

<p>Note that renumbering starts at the first number actually given, rather than restarting at the first possible number. To renumber from 1 (or A.) you must change the first numbered bullet to that.</p>

<p>If automatic renumbering isn&#39;t wanted, just specify the <code>&#39;renumber&#39;</code> option with a false value.</p>

<p>Note that normal numbers above 1000 at the start of a line are no longer considered to be paragraph numbering. Numbered paragraphs running that high are exceptionally rare, and much rarer than paragraphs that look like these:</p>

<pre><code>        Although it has long been popular (especially in the year
        2001) to point out that we now live in the Future, many
        of the promised miracles of Future Life have failed to
        eventuate. This is a new phenomenon (it didn&#39;t happen in
        1001) because the idea that the future might be different
        is a new phenomenon.</code></pre>

<p>which the former numbering rules caused to be formatted like this:</p>

<pre><code>        Although it has long been popular (especially in the year

        2001) to point out that we now live in the Future, many of the
              promised miracles of Future Life have failed to eventuate.
              This is a new phenomenon (it didn&#39;t happen in

        2002) because the idea that the future might be different is a
              new phenomenon.</code></pre>

<p>but which are now formatted:</p>

<pre><code>        Although it has long been popular (especially in the year 2001)
        to point out that we now live in the Future, many of the
        promised miracles of Future Life have failed to eventuate. This
        is a new phenomenon (it didn&#39;t happen in 1001) because the idea
        that the future might be different is a new phenomenon.</code></pre>

<p>If you want numbers less than 1000 (or other characters strings currently treated as bullets) to be ignored in this way, you can turn of list formatting entirely by setting the <code>&#39;lists&#39;</code> option to a false value.</p>

<p>You can also select which kinds of lists are recognized, by using a string as the value of lists:</p>

<pre><code>    # Don&#39;t recognize Roman numerals or alphabetics as list markers...
    autoformat { lists =&gt; &#39;number, bullet&#39; }, $text;

    # Don&#39;t recognize bullets or numbers as list markers...
    autoformat { lists =&gt; &#39;roman, alpha&#39; }, $text;

    # Recognize everything except Roman numerals as list markers...
    autoformat { lists =&gt; &#39;number, bullet, alpha&#39; }, $text;</code></pre>

<p>The string should contain one or more of the following words: <code>number</code>, <code>bullet</code>, <code>alpha</code>, <code>roman</code>. <code>autoformat()</code> will ignore any list type that doesn&#39;t appear in the <code>&#39;lists&#39;</code> string.</p>

<h2 id="Quoting">Quoting</h2>

<p>Another case in which contiguous lines may be interpreted as belonging to different paragraphs, is where they are quoted with distinct quoters. For example:</p>

<pre><code>        : &gt; CN&gt; So anyway, how can I stop reloads on a web page? Email
        : &gt; CN&gt; replies only, thanks - I don&#39;t read this newsgroup.
        : &gt; Begone, sirrah! You are a pathetic, Bill-loving,
        : &gt; microcephalic script-infant.
        : Sheesh, what&#39;s with this group - ask a question, get toasted!
        : And how *dare* you accuse me of Ianuphilia!</code></pre>

<p><code>autoformat</code> recognizes the various quoting conventions used in this example and treats it as three paragraphs to be independently reformatted.</p>

<p>You may also override the default set of recognized quoters by specifying a <code>&#39;quoter&#39;</code> argument when calling <code>autoformat()</code>. For example, to format lines such as:</p>

<pre><code>        // This is a comment
        // in the standard C(++)
        // comment-to-EOL
        // format</code></pre>

<p>specify:</p>

<pre><code>    autoformat($text, { quoter =E&lt;gt&gt; qr{//} })</code></pre>

<p>Instead of completely replacing the existing set of quoters, you can <i>extend</i> them by specifying a pattern that includes the metasequence <code>&lt;QUOTER&gt;</code>, which is then replaced by the module&#39;s standard pattern for quoters. So, for example, to add <code>//</code> to the set of existing quoters:</p>

<pre><code>    autoformat($text, { quoter =E&lt;gt&gt; qr{//|&lt;QUOTER&gt;} })</code></pre>

<p>Block quotations present a different challenge. A typical formatter would render the following quotation:</p>

<pre><code>        &quot;We are all of us in the gutter, but some of us are looking at
         the stars&quot;
                                -- Oscar Wilde</code></pre>

<p>like so:</p>

<pre><code>        &quot;We are all of us in the gutter, but some of us are looking at
        the stars&quot; -- Oscar Wilde</code></pre>

<p><code>autoformat</code> recognizes the quotation structure by matching the following regular expression against the text component of each paragraph:</p>

<pre><code>        / \A(\s*) # leading whitespace for quotation ([&quot;&#39;]|``) # opening
        quotemark (.*) # quotation (&#39;&#39;|\2) # closing quotemark \s*?\n #
        trailing whitespace after quotation (\1[ ]+) # leading
        whitespace for attribution
                                #   (must be indented more than
                                #   quotation)
          (--|-) # attribution introducer ([^\n]*?\n) # first
          attribution line ((\5[^\n]*?$)*) # other attribution lines
                                #   (indented no less than first line)
          \s*\Z # optional whitespace to end of paragraph /xsm</code></pre>

<p>When reformatted (see below), the indentation and the attribution structure will be preserved:</p>

<pre><code>        &quot;We are all of us in the gutter, but some of us are looking
         at the stars&quot;
                                -- Oscar Wilde</code></pre>

<h2 id="Widow-control"><a id="Widow"></a>Widow control</h2>

<p>Note that in the last example, <code>autoformat</code> broke the line at column 68, four characters earlier than it should have. It did so because, if the full margin width had been used, the formatting would have left the last two words by themselves on an oddly short last line:</p>

<pre><code>        &quot;We are all of us in the gutter, but some of us are looking at
        the stars&quot;</code></pre>

<p>This phenomenon is known as &quot;widowing&quot; and is heavily frowned upon in typesetting circles. It looks ugly in plaintext too, so <code>autoformat</code> avoids it by stealing extra words from earlier lines in a paragraph, so as to leave enough for a reasonable last line. The heuristic used is that final lines must be at least 10 characters long (though this number may be adjusted by passing a <code>widow =&gt; <i>minlength</i></code> argument to <code>autoformat</code>).</p>

<p>If the last line is too short, the paragraph&#39;s right margin is reduced by one column, and the paragraph is reformatted. This process iterates until either the last line exceeds nine characters or the margins have been narrowed by 10% of their original separation. In the latter case, the reformatter gives up and uses its original formatting.</p>

<h2 id="Justification">Justification</h2>

<p>The <code>autoformat</code> subroutine also takes a named argument: <code>{justify =&gt; <i>type</i>}</code>, which specifies how each paragraph is to be justified. The options are: <code>&#39;left&#39;</code> (the default), <code>&#39;right&#39;,</code> <code>&#39;centre&#39;</code> (or <code>&#39;center&#39;</code>), and <code>&#39;full&#39;</code>. These act on the complete paragraph text (but <i>not</i> on any quoters before that text). For example, with <code>&#39;right&#39;</code> justification:</p>

<pre><code>        R3&gt;     Now is the Winter of our discontent made
        R3&gt; glorious Summer by this son of York. And all
        R3&gt; the clouds that lour&#39;d upon our house In the
        R3&gt;              deep bosom of the ocean buried.</code></pre>

<p>Full justification is interesting in a fixed-width medium like plaintext because it usually results in uneven spacing between words. Typically, formatters provide this by distributing the extra spaces into the first available gaps of each line:</p>

<pre><code>        R3&gt; Now  is  the  Winter  of our discontent made
        R3&gt; glorious Summer by this son of York. And all
        R3&gt; the  clouds  that  lour&#39;d  upon our house In
        R3&gt; the deep bosom of the ocean buried.</code></pre>

<p>This produces a rather jarring visual effect, so <code>autoformat</code> reverses the strategy and inserts extra spaces at the end of lines:</p>

<pre><code>        R3&gt; Now is the  Winter of  our  discontent  made
        R3&gt; glorious Summer by this son of York. And all
        R3&gt; the clouds that lour&#39;d  upon  our  house  In
        R3&gt; the deep bosom of the ocean buried.</code></pre>

<p>Most readers find this less disconcerting.</p>

<h2 id="Implicit-centring"><a id="Implicit"></a>Implicit centring</h2>

<p>Even if explicit centring is not specified, <code>autoformat</code> will attempt to automatically detect centred paragraphs and preserve their justification. It does this by examining each line of the paragraph and asking: &quot;if this line were part of a centred paragraph, where would the centre line have been?&quot;</p>

<p>The answer can be determined by adding the length of leading whitespace before the first word, plus half the length of the full set of words on the line. That is, for a single line:</p>

<pre><code>        $line =~ /^(\s*)(.*?)(\s*)$/ $centre =
        length($1)+0.5*length($2);</code></pre>

<p>By making the same estimate for every line, and then comparing the estimates, it is possible to deduce whether all the lines are centred with respect to the same axis of symmetry (with an allowance of &plusmn;1 to cater for the inevitable rounding when the centre positions of even-length rows were originally computed). If a common axis of symmetry is detected, <code>autoformat</code> assumes that the lines are supposed to be centred, and switches to centre-justification mode for that paragraph.</p>

<p>Note that this behaviour can to switched off entirely by setting the <code>&quot;autocentre&quot;</code> argument false.</p>

<h2 id="Case-transformations"><a id="Case"></a>Case transformations</h2>

<p>The <code>autoformat</code> subroutine can also optionally perform case conversions on the text it processes. The <code>{case =&gt; <i>type</i>}</code> argument allows the user to specify six different conversions:</p>

<dl>

<dt id="&#39;upper&#39;"><a id="upper"></a><code>&#39;upper&#39;</code></dt>
<dd>

<p>This mode unconditionally converts every letter in the reformatted text to upper-case;</p>

</dd>
<dt id="&#39;lower&#39;"><a id="lower"></a><code>&#39;lower&#39;</code></dt>
<dd>

<p>This mode unconditionally converts every letter in the reformatted text to lower-case;</p>

</dd>
<dt id="&#39;sentence&#39;"><a id="sentence"></a><code>&#39;sentence&#39;</code></dt>
<dd>

<p>This mode attempts to generate correctly-cased sentences from the input text. That is, the first letter after a sentence-terminating punctuator is converted to upper-case. Then, each subsequent word in the sentence is converted to lower-case, unless that word is originally mixed-case or contains punctuation. For example, under <code>{case =&gt; &#39;sentence&#39;}</code>:</p>

<pre><code>        &#39;POVERTY, MISERY, ETC. are the lot of the PhD candidate. alas!&#39;</code></pre>

<p>becomes:</p>

<pre><code>        &#39;Poverty, misery, etc. are the lot of the PhD candidate. Alas!&#39;</code></pre>

<p>Note that <code>autoformat</code> is clever enough to recognize that the period after abbreviations such as <code>etc.</code> is not a sentence terminator.</p>

<p>If the argument is specified as <code>&#39;sentence &#39;</code> (with one or more trailing whitespace characters) those characters are used to replace the single space that appears at the end of the sentence. For example, <code>autoformat($text, {case=&gt;&#39;sentence &#39;}</code>) would produce:</p>

<pre><code>        &#39;Poverty, misery, etc. are the lot of the PhD candidate. Alas!&#39;</code></pre>

</dd>
<dt id="&#39;title&#39;"><a id="title"></a><code>&#39;title&#39;</code></dt>
<dd>

<p>This mode behaves like <code>&#39;sentence&#39;</code> except that the first letter of <i>every</i> word is capitalized:</p>

<pre><code>        &#39;What I Did On My Summer Vacation In Monterey&#39;</code></pre>

</dd>
<dt id="&#39;highlight&#39;"><a id="highlight"></a><code>&#39;highlight&#39;</code></dt>
<dd>

<p>This mode behaves like <code>&#39;title&#39;</code> except that trivial words are not capitalized:</p>

<pre><code>        &#39;What I Did on my Summer Vacation in Monterey&#39;</code></pre>

</dd>
<dt id="sub{...}"><a id="sub"></a><code>sub{...}</code></dt>
<dd>

<p>If the argument for <code>&#39;case&#39;</code> is a subroutine reference, that subroutine is applied to each word and the result replaces the word in the text.</p>

<p>For example, to convert a string to hostage-case:</p>

<pre><code>    my $ransom_note = sub {
        return join &quot;&quot;,                    # ^  Reconcatenate
               map {/[aeiou]/i ? lc : uc}  # |  uPPeR aND LoWeR each
               split //,                   # |  Break into chars
               shift;                      # |  Take argument
    };

    $text = autoformat($text, {case =&gt; $ransom_note });
    # &quot;FoR eXaMPLe, To CoNVeRT a STRiNG To HoSTaGe-CaSe:&quot;</code></pre>

<p>Or to highlight particular words:</p>

<pre><code>    my @SPECIAL = qw( perl camel wall );
    sub highlight_specials {
        my ($word) = @_;
        return $word ~~ @SPECIAL ? uc($word) : $word;
    }

    $text = autoformat($text, {case =&gt; \&amp;highlight_specials});
    # &quot;It is easier for a CAMEL to pass through a WALL of PERL...&quot;</code></pre>

</dd>
</dl>

<h2 id="Selective-reformatting"><a id="Selective"></a>Selective reformatting</h2>

<p>You can select which paragraphs <code>autoformat</code> actually reformats (or, rather, those it <i>doesn&#39;t</i> reformat) using the <code>&quot;ignore&quot;</code> flag.</p>

<p>For example:</p>

<pre><code>        # Reformat all paras except those containing &quot;verbatim&quot;...
        print autoformat { all =&gt; 1, ignore =&gt; qr/verbatim/i }, $text;

        # Reformat all paras except those less that 3 lines long...
        print autoformat { all =&gt; 1, ignore =&gt; sub { tr/\n/\n/ &lt; 3
        } }, $text;

        # Reformat all paras except those that are indented...
        print autoformat { all =&gt; 1, ignore =&gt; qr/^\s/m }, $text;

        # Reformat all paras except those that are indented (easier)...
        print autoformat { all =&gt; 1, ignore =&gt; &#39;indented&#39; }, $text;</code></pre>

<h2 id="Handling-tabs"><a id="Handling"></a>Handling tabs</h2>

<p>Text::Autoformat replaces any tabs in the text it&#39;s formatting with the appropriate number of spaces (using Text::Tabs to do its dirty work). It normally assumes that each tab is equivalent to 8 space characters, but you can change that default using the &#39;tabspace&#39; option:</p>

<pre><code>        print autoformat { tabspace =&gt; 4 }, $text;</code></pre>

<h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1>

<p><a href="https://metacpan.org/pod/Text::Reform">Text::Reform</a> - provides functions for manual text wrapping and reformatting.</p>

<p><a href="https://metacpan.org/pod/Text::Aligner">Text::Aligner</a> - provides a single function for justifying strings according to various styles.</p>

<p><a href="./Text::Format.html">Text::Format</a> - a class that provides methods for formatting text in various ways.</p>

<p><a href="https://metacpan.org/pod/Data::Formatter::Text">Data::Formatter::Text</a> - format various Perl data structures as text, in different ways according to the type of data.</p>

<h1 id="REPOSITORY">REPOSITORY</h1>

<p><a href="https://github.com/neilb/Text-Autoformat">https://github.com/neilb/Text-Autoformat</a></p>

<h1 id="AUTHOR">AUTHOR</h1>

<p>Damian Conway (damian@conway.org)</p>

<h1 id="BUGS">BUGS</h1>

<p>There are undoubtedly serious bugs lurking somewhere in code this funky :-) Bug reports and other feedback are most welcome.</p>

<h1 id="LICENCE-AND-COPYRIGHT"><a id="LICENCE"></a>LICENCE AND COPYRIGHT</h1>

<p>Copyright (c) 1997-2007, Damian Conway <code>&lt;DCONWAY@CPAN.org&gt;</code>. All rights reserved.</p>

<p>This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See <a href="https://metacpan.org/pod/perlartistic">perlartistic</a>.</p>

<h1 id="DISCLAIMER-OF-WARRANTY"><a id="DISCLAIMER"></a>DISCLAIMER OF WARRANTY</h1>

<p>BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE &quot;AS IS&quot; WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.</p>

<p>IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Text::Autoformat, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Text::Autoformat</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Text::Autoformat</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Text::Autoformat.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
